package zheezes.eisp.autotask.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.apache.log4j.Logger;

import zheezes.eisp.data.orm.CollectTask;
import zheezes.eisp.data.orm.Concentrator;


public class ResMeterDailyFrozenCollectTaskCreator extends
		AbstractAutoTaskCreator {
	private static final Logger logger = Logger.getLogger(ResMeterDailyFrozenCollectTaskCreator.class);
	
	static {
		logger.debug("loading");
	}
	
	@Override
	public List<CollectTask> mktask() {
		List<CollectTask> list = new ArrayList<CollectTask>();
		Calendar now = Calendar.getInstance();
		for (Concentrator con : dataAccessor.queryAllCons()) {
			CollectTask task = new CollectTask();
			task.setType(CollectTask.RM_DAILY_FROZEN_TASK);
			task.setDataDate(schedule.getTime());
			task.setCreateDate(now.getTime());
			Calendar tcal = (Calendar) now.clone(); // task will be terminated after 3 days from now
			tcal.add(Calendar.DATE, TASK_LAPSE);
			task.setLapseDate(tcal.getTime());
			task.setConId(con.getId());
			// task.setMinRunStep(0);
			task.setMinRunIntv(3600);
			task.setRunTimes(0);
			task.setStatus(CollectTask.STATUS_QUEUE);
			task.setSource(CollectTask.SOURCE_AUTO);
			task.setCollectTimes(-1);
			task.setMaxCommSuccNum(-1);
			task.setCommSuccNum(0);

			task.setTotalNum(dataAccessor.countResMeterByCon(con.getId()));
			task.setCollectedNum(dataAccessor.countResMeterWithDailyFrznByCon(con.getId(), schedule.getTime()));

			list.add(task);
		}
		return list;
	}

//	@Override
//	public int getType() {
//		// return RES_METER_DAILY_FROZEN_COLLECT_TASK;
//	}
}
